home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 3.7 KB | 107 lines |
- package symantec.itools.awt;
-
- import java.awt.*;
-
- // 02/03/97 LAB Fixed a type-o in the NOTE below.
- // 02/15/97 RKM Put gc and runFinalization in paintComponent
- // 02/16/97 RKM Changed paint call to update as per David E's suggestion
-
- //
- // NOTE: If you use this routine, you need to implement TransparencyTrick.
- // Otherwise intersecting your component with another componet that uses
- // these routines will result in a lock up
- //
-
- /**
- * This class implements the painting method that is used to simulate transparent
- * Components. If you use this class you also need to implement TransparencyTrick.
- * Otherwise intersecting your Component with another Component that uses
- * these routines will result in a lock up.
- */
- public class TransparencyTrickUtils
- {
- //
- // Implements transparency the bast we can under AWT
- //
- /**
- * This method implements the painting of transparent Components.
- * It does this by painting the Components parent and all the other
- * Components that intersect with the invisible Component.
- * @param drawingComponent the invisible Component "being drawn"
- * @param g the graphics context to use for drawing
- */
- public static void paintComponentsBehind
- (Component drawingComponent,
- Graphics g)
- {
- Rectangle myBounds = drawingComponent.bounds();
-
- //First fill my background with myParent
- Container myParent = drawingComponent.getParent();
- paintComponent(drawingComponent, (Component)myParent, myBounds, g);
-
- //Now draw any intersecting components
- Component[] list = myParent.getComponents();
- for (int i = 0; i < list.length; ++i) {
- Component c = list[i];
- if (c != drawingComponent)
- paintComponent(drawingComponent, c, myBounds, g);
- }
- }
-
- //
- // A utility of paintComponentsBehind
- //
-
- /**
- * This method paints one Component that intsects with the invisible
- * Component. It is a utility routine of paintComponentsBehind.
- * @param drawingComponent the invisible Component "being drawn"
- * @param intersectingComponent the Component that intersects the drawingComponent
- * @param myBounds the bounds of the invisible Component
- * @param g the graphics context to use for drawing
- * @see #paintComponentsBehind
- */
- public static void paintComponent
- (Component drawingComponent,
- Component intersectingComponent,
- Rectangle myBounds,
- Graphics g)
- {
- //If it's an invisible button, don't draw this component (avoid recursion)
- if (intersectingComponent instanceof TransparencyTrick)
- return;
-
- //Make certain intersectingComponent really does intersect us
- Rectangle icBounds = intersectingComponent.bounds();
- if (icBounds.intersects(myBounds)) {
- Image img = drawingComponent.createImage(icBounds.width, icBounds.height);
- if (img != null) {
- //Get the graphics object representing the image
- Graphics imageGraphics = img.getGraphics();
- if (imageGraphics != null) {
- //Draw the intersecting component into the offscreen image
- intersectingComponent.update(imageGraphics);
-
- //Draw it to the screen
- g.drawImage(img, icBounds.x - myBounds.x, icBounds.y - myBounds.y, null);
-
- imageGraphics.dispose();
- }
-
- //No use in waiting for the garbage collector, we know it's garbage
- img.flush();
-
- //Flush should call ImageRepresentation.dispose, but it is not,
- //so we'll have to make certain the finalize for the ImageRepresentation gets called
- //Since this is a big problem on the Macintosh, we'll only do it for them
- if (symantec.itools.lang.OS.isMacintosh())
- {
- System.gc();
- System.runFinalization();
- }
- }
- }
- }
- }
-